package common.bean;

import org.hibernate.transform.AliasedTupleSubsetResultTransformer;

import java.util.HashMap;
import java.util.Map;

public class DynamicResultTransformer extends AliasedTupleSubsetResultTransformer {


	public Object transformTuple(Object[] tuple, String[] aliases) {
		Map result = new HashMap(tuple.length);
		for ( int i=0; i<tuple.length; i++ ) {
			String alias = aliases[i];
			if ( alias!=null ) {
				result.put(convertAlias(alias),tuple[i]);
			}
		}
		return result;
	}
	
	public boolean isTransformedValueATupleElement(String[] aliases,
			int tupleLength) {
		
		return false;
	}
	
	private String convertAlias(String alias){
		   String[] tmp = alias.split("_");
		   String result = null;
		   for(int n = 0; n < tmp.length ;n++){
			   if(n == 0){
				   result = tmp[n].toLowerCase();
			   }else{
				   result += tmp[n].substring(0, 1) + tmp[n].substring(1).toLowerCase();
			   }
		   }
		   return result;
	}

}
